using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Light
{
    public class SwitchBar : MonoBehaviour
    {
        //��ѡ�к��Ӧ����ɫ
        [SerializeField] private Color selectColor;

        //��������ɫ
        [SerializeField] private Color sourceColor;

        //��¼��ǰ��Ծ���������
        private int curActiveObjIndex;

        private List<(Image, GameObject)> imageUIList;

        //����������Χ
        public int CurActiveObjIndex
        {
            private set
            {
                if (value >= imageUIList.Count) value = 0;
                if (value < 0) value = imageUIList.Count - 1;
                SwitchActiveUI(value); //֪ͨUI�ı���ɫ
                curActiveObjIndex = value;
            }
            get => curActiveObjIndex;
        }


        private void Awake()
        {
            imageUIList = new List<(Image, GameObject)>
            {
                //��ȡ��ӦUIͼƬ
                (transform.Find("Map").GetComponent<Image>(), transform.parent.Find("MainBar/Map").gameObject),
                (transform.Find("Quest").GetComponent<Image>(), transform.parent.Find("MainBar/Quest").gameObject),
                (transform.Find("Goods").GetComponent<Image>(), transform.parent.Find("MainBar/Goods").gameObject),
                (transform.Find("BluePrint").GetComponent<Image>(),
                    transform.parent.Find("MainBar/BluePrint").gameObject),
                (transform.Find("Skill").GetComponent<Image>(), transform.parent.Find("MainBar/Skill").gameObject),
                (transform.Find("Level").GetComponent<Image>(), transform.parent.Find("MainBar/Level").gameObject)
            };
        }

        private void Start()
        {
            CurActiveObjIndex = (int)SwitchBarUI.Goods;
        }

        private void Update()
        {
            if (LightInputManager.Instance.StatusBarTopMoveLeftInput) CurActiveObjIndex--;

            if (LightInputManager.Instance.StatusBarTopMoveRightInput) CurActiveObjIndex++;
        }

        private void SwitchActiveUI(int targetIndex)
        {
            //��Ծ�������
            imageUIList[CurActiveObjIndex].Item1.color = sourceColor;
            imageUIList[curActiveObjIndex].Item2.SetActive(false);

            imageUIList[targetIndex].Item1.color = selectColor;
            imageUIList[targetIndex].Item2.SetActive(true);
        }

        private enum SwitchBarUI
        {
            Map,
            Quest,
            Goods,
            BluePrint,
            Skill,
            Level
        }
    }
}